/*Description:  This is a linked list of Cards.  See deck.h*/

//cardstack.h
//by Eric Norton
//2/13/02

#ifndef CARDSTACK_H
#define CARDSTACK_H

#include <sys/types.h>   //do I need the all of the next three includes?
#include <sys/timeb.h>
#include <stdlib.h>
#include <time.h>

const char CHEART='h';		//denotes "hearts" suit in Card struct
const char CDIAMOND='d';	//obvious
const char CSPADE='s';
const char CCLUB='c';
const int IDECKSIZE=44;		//obvious	CHANGED FOR HORSERACE GAME
const int ISUITS=4;	
const int IRACE=IDECKSIZE/ISUITS;	//number of cards per suit
const int IMAX=1000;				//max #of IDECKSIZE decks in class Deck
const int IMIN=1;					//min #

//this struct is what each card is, it contains all
//information about each card
struct Card
{
	//PRECONDITION: none
	//POSTCONDITION: pointers set to NULL
	Card::Card();
	//PRE: expects Card
	//POST: Card whose member function was called
	//becomes copy of parameter but pointers are unaffected
	void operator=(const Card& copyme);

	char csuit;		//suit of card
	int inum;		//1-IRACE for A-K
	Card* next;		//for linked list of Cards
	Card* prev;
};

//this is a linked list of Cards
class Cardstack
{
public:
	//PRE: none
	//POST: pointers set to NULL
	Cardstack();
	//PRE: expects Card
	//POST: new Card put on end of list is copy of parameter
	bool Give(const Card& newcard);
	//PRE: expects Card
	//POST: new Card put on head of list is copy of parameter
	bool Givehead(const Card& newcard);
	//PRE: none
	//POST: linked list is destroyed
	void Zap();
	//PRE: none
	//POST: linked list is output from beginning to end
	void Print();
	//PRE: expects integer [1,last Card]
	//POST: that Card is copied and destroyed and copy is returned, if iCard<1
	//or iCard>last Card function assumes iCard==1 or iCard==last Card, if
	//list is empty, empty Card is returned
	Card Take(int iCard);
	//PRE: none
	//POST: list is shuffled
	bool Shuffle();
	//PRE: none
	//POST: random number [0,999] is returned
	int Time();
	//PRE: none
	//POST: random number [0,isize-1] is returned
	int Random();
	//PRE: none
	//POST: returns inumth [0,isize-1] Card
	Card Getcard(int inum);
	//PRE: none
	//POST: calls Zap()
	~Cardstack();
	//lets Deck class access isize
	friend class Deck;
private:
	Card* head;		//head of linked Card list
	Card* tail;
	Card* cursor;	//traverses linked list
	int isize;		//size of linked Card list
};

#endif